





************************************************************;
** Create Matched HEDIS2003 matched with Denominator file **;
************************************************************;

options ls=76 nofmterr;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata';
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata';
libname plan '/data/Medicare_P01_2009/data/HEDIS/plandata';


data a01; set raw.hmoid03;

     length org_id $ 5;
     org_id=hcfacont;

     proc sort; by sub_id;

data a02; set raw.hedis2003orig;

     hic_number=hic_num;
     m_months = m_month;

     proc sort; by sub_id;

data a(drop=hic_num m_month); merge a01 a02(in=ok); by sub_id;
  
     if ok;

     length hic_org $ 18 ;
     hic_org=org_id||'-'||hic_number;

     ** Invalid HIC number Indicators **;

     if substr(hic_number,2,11)=' ' or
        substr(hic_number,3,10)=' ' or 
        substr(hic_number,4,9) =' ' or
        substr(hic_number,5,8) =' ' then short_hic=1; else short_hic=0;

      if hic_number=' ' or
         hic_number='00000' or
         hic_number='000000' or
         hic_number='0000000' or
         hic_number='00000000' or
         hic_number='000000000' or
         hic_number='0000000000' or
         hic_number='00000000000' or
         hic_number='000000000000' or

         hic_number='99999' or
         hic_number='999999' or
         hic_number='9999999' or
         hic_number='99999999' or
         hic_number='999999999' or
         hic_number='9999999999' or
         hic_number='99999999999' or
         hic_number='999999999999' or  
         hic_number='Error'   or
         hic_number='UNKNOWN' then invalid_hic=1; else invalid_hic=0; 

         proc freq;
              tables short_hic invalid_hic;
              title 'HEDIS2003 HIC Number of M_Months Check';
    
  data a01; set a;

       **** Exclude Invalid Cases ****;

       if short_hic=1   then delete;
       if invalid_hic=1 then delete;

       proc freq; tables m_months;

  data a0; set a01;

       if m_months=0  then delete;

       proc sort; by hic_org;

    data a1; set a0;

         proc means n sum nway noprint;
              class hic_org;
              var m_months;
              output out=totmon0 sum=totmonth;

    data totmon; set totmon0;
         
         keep hic_org totmonth;

         proc freq;
              tables totmonth;
              title 'HEDIS2003 - Total Months in one contract';
        
         proc sort nodupkey; by hic_org;
 
    data a02(drop=short_hic invalid_hic); merge a0(in=ok) totmon; by hic_org;

         if ok;
 
         proc freq;
              tables totmonth;

    data a2; set a02;

         if totmonth>12 then delete;

         id_num=_n_;

         proc sort; by org_id;


         *** Outpupt LINKID2003 ***;

     data raw.linkid2003; set a2;

          keep hic_number id_num;

     
        *** Add Plan Type Information ***;

     
      data plan0; set plan.hedis2003planinfo;

           length org_id $ 5;
           org_id    = hcfa_contract_number ;
           plan_type = general_11;

        data plan; set plan0;

             keep org_id plan_type;
             proc sort; by org_id;


    *** Output HEDIS2003 ***;

    data hed03(drop=hic_number can); merge a2(in=ok) plan; by org_id;

         if ok;

         if totmonth>12 then delete; /** drop cases with more than 1 year months in one contract **/

         denom_flag=1;  /** checked this hedis2003 dataset all linked to Denominator file **/

         length racec gender agec $ 10;

         if race=1 then racec='1.White';
         if race=2 then racec='2.Black';
         if race=3 then racec='3.Other';
         if race=4 then racec='4.Asian';
         if race=5 then racec='5.Hispanic';
         if race=6 then racec='6.Native';
         if (race=0 or race=.) then racec='0.Unknown';

         if sex=1 then gender='1.Male';
         if sex=2 then gender='2.Female';

         if age>0   and age<20 then agec='1-20 yr';
         if age>=20 and age<30 then agec='20-29 yrs';
         if age>=30 and age<40 then agec='30-39 yrs';
         if age>=40 and age<50 then agec='40-49 yrs';
         if age>=50 and age<60 then agec='50-59 yrs';
         if age>=60 and age<65 then agec='60-64 yrs';
         if age>=65 and age<70 then agec='65-69 yrs';
         if age>=70 and age<75 then agec='70-74 yrs';
         if age>=75 and age<80 then agec='75-79 yrs';
         if age>=80 and age<85 then agec='80-84 yrs';
         if age>=85            then agec='85 + yrs';

         **-- Creat Age 10-year category --**;

         agen=1*age;
         length agec2 $ 5;

         if agen>=65 and agen<75 then agec2='65-74';
         if agen>=75 and agen<85 then agec2='75-84';
         if agen>=85             then agec2='85+';


         **-- State and Region Variable --**;

    if state='01' then state_ab='AL' ;    if state='02' then state_ab='AK' ;
    if state='03' then state_ab='AZ' ;    if state='04' then state_ab='AR' ;
    if state='05' then state_ab='CA' ;    if state='06' then state_ab='CO' ;
    if state='07' then state_ab='CT' ;    if state='08' then state_ab='DE' ;
    if state='09' then state_ab='DC' ;    if state='10' then state_ab='FL' ;

    if state='11' then state_ab='GA' ;    if state='12' then state_ab='HI' ;
    if state='13' then state_ab='ID' ;    if state='14' then state_ab='IL' ;
    if state='15' then state_ab='IN' ;    if state='16' then state_ab='IA' ;
    if state='17' then state_ab='KS' ;    if state='18' then state_ab='KY' ;
    if state='19' then state_ab='LA' ;    if state='20' then state_ab='ME' ;

    if state='21' then state_ab='MD' ;    if state='22' then state_ab='MA' ;
    if state='23' then state_ab='MI' ;    if state='24' then state_ab='MN' ;
    if state='25' then state_ab='MS' ;    if state='26' then state_ab='MO' ;
    if state='27' then state_ab='MT' ;    if state='28' then state_ab='NE' ;
    if state='29' then state_ab='NV' ;    if state='30' then state_ab='NH' ;

    if state='31' then state_ab='NJ' ;    if state='32' then state_ab='NM' ;
    if state='33' then state_ab='NY' ;    if state='34' then state_ab='NC' ;
    if state='35' then state_ab='ND' ;    if state='36' then state_ab='OH' ;
    if state='37' then state_ab='OK' ;    if state='38' then state_ab='OR' ;
    if state='39' then state_ab='PA' ;    if state='40' then state_ab='PR';

    if state='41' then state_ab='RI' ;    if state='42' then state_ab='SC' ;
    if state='43' then state_ab='SD' ;    if state='44' then state_ab='TN' ;
    if state='45' then state_ab='TX' ;    if state='46' then state_ab='UT' ;
    if state='47' then state_ab='VT' ;    if state='48' then state_ab='GU';
    if state='49' then state_ab='VA' ;    if state='50' then state_ab='WA' ;

    if state='51' then state_ab='WV' ;    if state='52' then state_ab='WI' ;
    if state='53' then state_ab='WY' ;    


    length region9 region4 $ 25; 

    if state_ab in ('CT','MA','ME','NH','RI','VT')                then region9='1.New England';
    if state_ab in ('NJ','NY','PA')                               then region9='2.Mid Atlantic'; 
    if state_ab in ('WI','MI','IL','IN','OH')                     then region9='3.East North Central'; 
    if state_ab in ('ND','SD','NE','KS','MN','IA','MO')           then region9='4.West North Central'; 
    if state_ab in ('DE','MD','DC','FL','GA','NC','SC','VA','WV') then region9='5.South Atlantic';
    if state_ab in ('KY','TN','MS','AL')                          then region9='6.East South Central'; 
    if state_ab in ('OK','AR','TX','LA')                          then region9='7.West South Central';
    if state_ab in ('MT','ID','WY','NV','UT','CO','AZ','NM')      then region9='8.Mountain'; 
    if state_ab in ('WA','OR','CA','HI','AK')                     then region9='9.Pacific';

    if  region9='1.New England'  or 
        region9='2.Mid Atlantic'       then region4='Region 1: Northeast';
    if  region9='3.East North Central' or 
        region9='4.West North Central' then region4='Region 2: Midwest';
    if  region9='5.South Atlantic' or 
        region9='6.East South Central' or 
        region9='7.West South Central' then region4='Region 3: South';
     if region9='8.Mountain' or 
        region9='9.Pacific'            then region4='Region 4: West';

         zip5=1*substr(zip,1,5);
      
         proc sort; by zip5;

 data zip; set new.zipinfo;

        proc sort; by zip5;

 data new.hedis2003; merge hed03(in=ok) zip; by zip5;

      if ok;

      if sub_id=6626 then org_id='HS524';
      if sub_id=6628 then org_id='HN524';

      proc contents data=new.hedis2003 varnum;

      proc freq; tables totmonth denom_flag plan_type;
                 title 'HEDIS 2003 data';


endsas;







